// Author	: damphat@gmail.com
// Created	: 01/12/2008

#pragma once
#include "vn/IOCommon.h"

#define STREAM_NOT_SUPPORTED throw NotSupportedException(__FUNCTION__);


IO_BEGIN

enum SeekOrigin {
	SeekBegin,
	SeekCurrent,
	SeekEnd
};

class Stream {
public:
	virtual StmLen	Read (Buf8 *buf,		StmLen len) = 0;
	virtual void	Write(const Buf8 *buf,	StmLen len) = 0;
	virtual StmPos	Seek (StmOff offset,	SeekOrigin origin) = 0;

	virtual void	Flush() = 0;
	virtual void	Close() = 0;

	virtual bool	CanRead()  = 0;
	virtual bool	CanWrite() = 0;
	virtual bool	CanSeek()  = 0;

	virtual StmPos	GetPosition() = 0;
	virtual void	SetPosition(StmPos pos) = 0;

	virtual StmLen	GetLength()   = 0;
	virtual void	SetLength(StmLen len)   = 0;

	virtual ~Stream() {
	}

	// CanTimeout 
	// ReadTimeout 
	// WriteTimeout 

	// Check whether end of stream?
	// Is this stream copyable?
	// Blocking vs Timeout?
	// the relation between stream length and stream position

};

IO_END

// TOTHINK:
// Socket use 'int' not 'size_t'
// Stream::Write(...) return int or void
// Stream should act like null stream => lacking when derive

// TOTHINK:
// We have hierarchy:
// class Stream
//		class FileStream
//		class NetworkStream
//
// Design should avoid:
// Stream x(FileStream(...));
